import QtQuick 2.12
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.9
import Quick.UIComponent.Dialog.Message 0.1
import Quick.UIComponent.Dialog.PageDialog 0.1
import Quick.UIComponent.Dialog.PopupIndicator 0.1


Page{
    id:root
    title: "Button"
    Rectangle{
        anchors.fill: parent
        color: "darkgreen"
    }

    Popup{
        id: popup
        width: root.width
        height: root.height
        modal: true
        focus: true
        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
    }


    Popup {
        id: popup1
        y: 100
        width: 400
        height: 400
        modal: true


        background: Rectangle {
            implicitWidth: 200
            implicitHeight: 200
            border.color: "green"
            color: "black"
        }
        contentItem: Column {
            Label{
                text: qsTr("自定义PopUp")
            }
            DialogButtonBox{
                Button {
                    text: qsTr("Save")
                    DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
                }
                Button {
                    text: qsTr("Close")
                    DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole
                }
                onAccepted: console.log("Ok clicked")
                onRejected:popup1.close()
                onDiscarded: popup1.close()
            }
        }


     }

    Dialog{
        id:dialog
        y: 100
        width: 400
        height: 400
        title: qsTr("系统Dialog")
        modal: true

        footer:DialogButtonBox {
            standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel
            onAccepted: console.log("Ok clicked")
            onRejected:dialog.close()
        }

    }

    DropArea {
        anchors.fill: parent
        Rectangle {
            anchors.fill: parent
            color: "green"
            visible: parent.containsDrag
        }
    }


    Message{
        id:message
        label:"窗前明月"
    }

    PageDialog{
        id:deletege
        title:"窗前明月"
    }

    PopupIndicator{
        id:popupIndic
        target:indicator1
    }


    Row{
        x:10
        y:10
        anchors.fill: parent
        Button{
            id:customBtn
            text: "下角标"
            width: 120
            height: 60
            onClicked: {
                popupIndic.width = 400
                popupIndic.height = 220
                popupIndic.dirction = "bottom"
                popupIndic.open()
            }
        }

        Button{
            id:customBtn1
            text: "左角标"
            width: 120
            height: 60
            onClicked: {
                popupIndic.width = 400
                popupIndic.height = 200
                popupIndic.dirction = "left"
                popupIndic.open()
            }
        }

        Button{
            id:customBtn2
            text: "右角标"
            width: 120
            height: 60
            onClicked: {
                popupIndic.open()
            }
        }
    }

    Rectangle{
        id:indicator1
        color: "red"
        width: 20
        height: 20
        anchors.centerIn: parent
    }


    Action {
        id: _system
        text: qsTr("系统popup")
        icon.source: "qrc:/image/icons/error.svg"
        onTriggered: popup.open()
    }
    Action {
        id: _custom
        text: qsTr("自定义例子")
        icon.source: "qrc:/image/icons/error.svg"
        onTriggered: popup1.open()
    }
    Action {
        id: _popup
        text: qsTr("系统dialog")
        icon.source: "qrc:/image/icons/error.svg"
        onTriggered: dialog.open()
    }
    Action {
        id: _message
        text: qsTr("Message")
        icon.source: "qrc:/image/icons/error.svg"
        onTriggered: message.open()
    }

    Action {
        id: _delete
        text: qsTr("Deletege")
        icon.source: "qrc:/image/icons/error.svg"
        onTriggered: deletege.open()
    }
    Action {
        id: _popInd
        text: qsTr("PopInd")
        icon.source: "qrc:/image/icons/error.svg"
        onTriggered: popupIndic.open()
    }



    footer:ToolBar {
        Row {
            anchors.fill: parent
            spacing: 10
            ToolButton { action: _system }
            ToolButton { action: _custom }
            ToolButton { action: _popup }
            ToolButton { action: _message }
            ToolButton { action: _delete }
            ToolButton { action: _popInd }
        }
    }

}
